import { z } from "zod"; import { guarded, json, body } from "@/lib/api"; import { branchConversation, activateBranch } from "@/lib/chat/store"; /** POST {messageId} → fork into a new conversation; POST {activate: messageId} → switch active sibling in place. */ export const POST = guarded<{ id: string }>(async (req, { params }) => { const b = await body(req, z.object({ messageId: z.string().optional(), activate: z.string().optional() })); if (b.activate) { await activateBranch(params.id, b.activate); return json({ ok: true }); } if (!b.messageId) return json({ error: "messageId requis" }, { status: 400 }); const conv = await branchConversation(params.id, b.messageId); return json({ conversation: conv }, { status: 201 }); });